﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset=UTF-8>
		<title>myCountDown - Vos propres compte à rebour en ligne !</title>
		<link type="text/css" rel="stylesheet" href="./main.css">
		<link type="text/css" rel="stylesheet" href="./countdown.css">
		<link type="text/css" rel="stylesheet" href="./jquery-ui-1.8.21.custom/css/redmond/jquery-ui-1.8.21.custom.css">
		<script type="text/javascript" src="scripts.js"></script>
		<script type="text/javascript" src="./jquery-ui-1.8.21.custom/js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="./jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>

		<script type="text/javascript">
		
			var targetTime;
		
			$(function() {
			targetTime = new Date(parseInt($('#tsval').val()*1000));
			targetTime.a
			alert(targetTime);
			if (targetTime)
			{
				rebour();
			}
			else
			{
				
			}
			});
			
				$(function() {
					$( "#ct" ).datepicker();
					//$.datepicker.formatDate( "dd MM yy", new Date());
				});
	
			
			function rebour()
			{
				var myCountDown = targetTime - new Date().getTime();
				if (myCountDown < 0) 
				{
					$('#countdown').text('Done !');
				}
				else
				{
					
					var year, month, day, hour, min, sec, msec;
					var d = new Date(myCountDown);
					day =d.getDay(); 
					month =d.getMonth(); 
					year =d.getFullYear(); 
					hour =d.getHours(); 
					min =d.getMinutes(); 
					sec =d.getSeconds(); 
					msec = d.getMilliseconds();
					year = year-1970;
					year = makeIt2Digits(year);
					month = makeIt2Digits(month);
					hour = makeIt2Digits(hour);
					min = makeIt2Digits(min);
					day = makeIt2Digits(day);
					sec = makeIt2Digits(sec);
					
					msec = ""+ msec;
					if (msec.length == 1)
						msec = '00'+msec;
					if (msec.length == 2)
						msec = '0'+msec;
					
					$('#countdown').text(year + "a " + month + "m " + day + "d " + hour + ":" + min + ":" + sec + '');
					setTimeout(rebour, 100)
				}
			}
			
			function makeIt2Digits(str)
			{
				str = ""+str;
				if (str.length == 1 )
				{
					str = '0'+str;
				}
				return str;
			}
		</script> 
	</head>		
	<body>
		<!-- <header>
			<ul>
				<a href="index.html">
				</a>
			</ul>
		</header> -->
		<content>
											
						<?php 
							if (isset($_GET['ref']))
							{
							//on affiche le countdown
							include("connexionbdd.php");
							
							$retour = mysql_query('SELECT * FROM cd WHERE ref =\''. $_GET['ref'].'\'');
    
							$donnees = mysql_fetch_array($retour);
							
							$message_attente = $donnees['waitingtext'];
							$message_fin = $donnees['resulttext'];
							
							
							var_dump($donnees['datevalue']);
							
							$dt = date_create_from_format('Y-m-d H:i:s', $donnees['datevalue']);
							$dt = date_default_timezone_set('Europe/Paris');
							var_dump($dt);
														
							$ts = date_timestamp_get($dt);

						?>
						<!-- <p id="introMessage"> Something will happen to you in : </p> -->
						<div id="countdown"><?php echo $donnees['datevalue']; ?></div>
						<!-- <p> Your waiting message : </p> -->
						
						<input type="hidden" id="tsval" value="<?php echo $ts; ?>"/>
						<p id="waitingMessage"><?php echo $message_attente; ?></p>
						<?php
						}
						else
						{
							include 'newCD.php' ;	
						}
						?>
						
				
		</content>
		<footer>
			
		</footer>
	</body>
	
</html>																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																								
